#include "controlDevice.h"
#include <stdlib.h>

/*

struct controlDevice
{
    char name[128]; // 设备名称
    int pin;  // 设别引脚
    int pinStatus; // 引脚状态
    int pinMode; // 引脚模式
    int (*deviceInit)(); // 初始化函数
    int (*open)(); // 打开函数
    int (*close)(); // 关闭函数
    int (*clearConfig)(); // 清除内存

    struct controlDevice *Next;
};


 */

int fansOpen(void);

int fansClose(void);

int fansClear(void);

int fansInit(void);


struct controlDevice fans = {
    .name       = "fans",
    .pin        = 23,
    .pinStatus  = HIGH,
    .pinMode    = OUTPUT,
    .deep_flag  = 1,
    .deviceInit = fansInit,
    .open       = fansOpen,
    .close      = fansClose,
    .clearConfig= fansClear
};


int fansOpen(void)
{
    digitalWrite(fans.pin,LOW);
    fans.pinStatus = LOW;
}

int fansClose(void)
{
    digitalWrite(fans.pin,HIGH);
    fans.pinStatus = HIGH;
}

int fansClear(void)
{
    
}


int fansInit(void)
{
    pinMode(fans.pin,fans.pinMode);
    digitalWrite(fans.pin,fans.pinStatus);    
}

struct controlDevice* addFansToDeviceLink(struct controlDevice* phead)
{
    if(phead == NULL)
    {
        return &fans;
    }
    else
    {
        fans.Next = phead;
        phead = &fans;
        return phead;
    }

}

